<!DOCTYPE html>
<html lang="en">
<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <style>
    .out {
      position: relative;
      width: 300px;
      height: 300px;
      background-color: #bfa;
      margin: 0 auto;
    }

    .inner {
      /* 这种居中的方式，只适用于元素的大小确定 */
      position: absolute;
      width: 100px;
      height: 100px;
      background-color: orange;
      left: 0;
      right: 0;
      top: 0;
      bottom: 0;
      margin: auto;
    }

  </style>
</head>
<body>
  <div class="out">
    <div class="inner"></div>
  </div>
</body>
</html>